package utils;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.text.DecimalFormat;
import java.util.Collections;
import java.util.HashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import objects.cluster.ClusterInfo;
import objects.user.UserInfo;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;



import jobqueue.JobQueueImpl;
import jobqueue.Scheduler;


import database.ConnectionManager;
import database.Database;

public class Utils {
	public static final boolean DEBUG = true;
	public static final boolean INFO = !DEBUG;
	public static JobQueueImpl jobQueue = new JobQueueImpl();
	public static Scheduler sched = new Scheduler(jobQueue);
	public static ExecutorService exec = Executors.newCachedThreadPool(); 
	public static DecimalFormat f = new DecimalFormat("##.00"); 
	public static final Log LOG = LogFactory.getLog(Utils.class);
	
	
	public static void out(Object o)
	{
		if(DEBUG)
			System.out.println(o.toString());
		if(INFO)
			LOG.info(o.toString());
			
	}
	
	public static String MD5(String pass) throws Exception {
		MessageDigest m = MessageDigest.getInstance("MD5");
		byte[] data = pass.getBytes(); 
		m.update(data,0,data.length);
		BigInteger i = new BigInteger(1,m.digest());
		return String.format("%1$032X", i);
	}

	
	public static int ConvertWalltime(String w)
	{
		String [] a = w.split(":");
		return Integer.parseInt(a[2])+ Integer.parseInt(a[1])*60 + Integer.parseInt(a[0])*3600;
	}
}
